//@formatter:off
/*********************************************************************************************************************************************************************************
 * #######################
 * #   FILE DESCRIPTOR   #
 * #######################
 * Application: BiblioteQOnline
 * Package: org.biblioteq.web.backing
 * File: A_Settings_SummaryPage_Backing.java
 * 
 * #######################
 * #   GNU DISCLAIMER    #
 * ####################### 
 * BiblioteQ Online is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version. BiblioteQ Online is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
 * 
 * #######################
 * #       Purpose       #
 * #######################
 * This backing bean provides all the methods required by the Summary Page Settings page.
 *
 * #######################
 * #      Revision       #
 * ####################### 
 * Jun 3, 2012, Clinton Bush, 1.0.0,
 *    New file.
 * 
 ********************************************************************************************************************************************************************************** 
 */
//@formatter:on
package org.biblioteq.web.backing;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

import org.apache.log4j.Logger;
import org.biblioteq.ejb.interfaces.SettingBusinessLocal;
import org.biblioteq.web.common.Constants;

/**
 * This backing bean provides all the methods required by the Summary Page Settings page.
 * 
 * @author Clint Bush
 * 
 */
@ManagedBean(name = "A_Settings_SummaryPage_Backing")
@ViewScoped
public class A_Settings_SummaryPage_Backing implements Serializable
{
	/**
	 * GUID for implementing Serializable.
	 */
	private static final long serialVersionUID = -8463159263216789327L;
	
	/**
	 * Get the logger.
	 */
	private static Logger log = Logger.getLogger(A_Settings_SummaryPage_Backing.class);
	
	/**
	 * Import the SettingBusiness EJB.
	 */
	@EJB(name = "SettingBusinessLocal")
	SettingBusinessLocal settingEjb;
	
	/**
	 * Get a copy of the Page_Backing bean. This will be injected via the setPageBackingBean(Page_Backing pageBackingBean) method.
	 */
	@ManagedProperty("#{Page_Backing}")
	private Page_Backing pageBackingBean;
	
	private boolean showItemsOut = false;
	private boolean showItemsRequested = false;
	private boolean showItemsOverdue = false;
	private boolean showOverdueFees = false;
	
	/**
	 * This method pre-populates the settings on this page from the database.
	 */
	@PostConstruct
	public void init()
	{
		this.setShowItemsOut(this.settingEjb.getBooleanSettingByName(Constants.SETTING_SHOW_ITEMS_OUT));
		this.setShowItemsRequested(this.settingEjb.getBooleanSettingByName(Constants.SETTING_SHOW_ITEMS_REQUESTED));
		this.setShowItemsOverdue(this.settingEjb.getBooleanSettingByName(Constants.SETTING_SHOW_ITEMS_OVERDUE));
		this.setShowOverdueFees(this.settingEjb.getBooleanSettingByName(Constants.SETTING_SHOW_FEES_OWED));
	}
	
	/**
	 * Returns true if Show Items Out is set; false, otherwise.
	 * 
	 * @return (boolean) The showItemsOut setting.
	 */
	public boolean isShowItemsOut()
	{
		return this.showItemsOut;
	}
	
	/**
	 * Returns true if Show Items Overdue is set; false, otherwise.
	 * 
	 * @return (boolean) The showItemsOverdue setting.
	 */
	public boolean isShowItemsOverdue()
	{
		return this.showItemsOverdue;
	}
	
	/**
	 * Returns true if Show Items Requested is set; false, otherwise.
	 * 
	 * @return (boolean) The showItemsRequested setting.
	 */
	public boolean isShowItemsRequested()
	{
		return this.showItemsRequested;
	}
	
	/**
	 * Returns true if Show Overdue Fees is set; false, otherwise.
	 * 
	 * @return (boolean) The showOverdueFees setting.
	 */
	public boolean isShowOverdueFees()
	{
		return this.showOverdueFees;
	}
	
	/**
	 * Saves the Summary Page settings.
	 * 
	 * @param e
	 *            (ActionEvent) The ActionEvent generated by the UI element that called this method (i.e. the Save button).
	 */
	public void save(ActionEvent e)
	{
		// Persist the settings
		this.settingEjb.saveSetting(Constants.SETTING_SHOW_ITEMS_OUT, String.valueOf(this.showItemsOut));
		this.settingEjb.saveSetting(Constants.SETTING_SHOW_ITEMS_REQUESTED, String.valueOf(this.showItemsRequested));
		this.settingEjb.saveSetting(Constants.SETTING_SHOW_ITEMS_OVERDUE, String.valueOf(this.showItemsOverdue));
		this.settingEjb.saveSetting(Constants.SETTING_SHOW_FEES_OWED, String.valueOf(this.showOverdueFees));
		
		// Display the Successful Save dialog
		this.pageBackingBean.showInfoMessage("Success!", "Your changes have been successfully saved!");
	}
	
	/**
	 * Used to inject the Page_Backing.java bean into this class.
	 * 
	 * @param pageBackingBean
	 *            (Page_Backing) The pageBackingBean to set.
	 */
	public void setPageBackingBean(Page_Backing pageBackingBean)
	{
		this.pageBackingBean = pageBackingBean;
	}
	
	/**
	 * Sets the Show Items Out setting.
	 * 
	 * @param showItemsOut
	 *            (boolean) The showItemsOut setting.
	 */
	public void setShowItemsOut(boolean showItemsOut)
	{
		this.showItemsOut = showItemsOut;
	}
	
	/**
	 * Sets the Show Items Overdue setting.
	 * 
	 * @param showItemsOverdue
	 *            (boolean) The showItemsOverdue setting.
	 */
	public void setShowItemsOverdue(boolean showItemsOverdue)
	{
		this.showItemsOverdue = showItemsOverdue;
	}
	
	/**
	 * Sets the Show Items Requested setting.
	 * 
	 * @param showItemsRequested
	 *            (boolean) The showItemsRequested setting.
	 */
	public void setShowItemsRequested(boolean showItemsRequested)
	{
		this.showItemsRequested = showItemsRequested;
	}
	
	/**
	 * Sets the Show Overdue Fees setting.
	 * 
	 * @param showOverdueFees
	 *            (boolean) The showOverdueFees setting.
	 */
	public void setShowOverdueFees(boolean showOverdueFees)
	{
		this.showOverdueFees = showOverdueFees;
	}
}
